﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
using DevExpress.XtraReports;
using DevExpress.XtraReports.UI;
namespace Exact_Extension
{
    public partial class MsgPrintDN : DevExpress.XtraEditors.XtraForm
    {
        ISHCMC_Invoice Inv;
        Common common;
        ExactDataContext DS;
        public MsgPrintDN(ISHCMC_Invoice _Inv,ExactDataContext _DS)
        {
            InitializeComponent();
            Inv = _Inv;
            DS = _DS;
            common = new Common(DS);
           
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
      
            ISHCMC_V_StudentListWithDebtor student = DS.ISHCMC_V_StudentListWithDebtors.Single(c => c.StudentID == Inv.StudentID);
            
            List<ISHCMC_ListInvoiceDetail_DebitNote> ListInvDetail = new List<ISHCMC_ListInvoiceDetail_DebitNote>();
            if (this.comboBoxEdit1.SelectedIndex ==0)
            {
                ListInvDetail.Add(common.GetInvoiceDetail(Inv, "APPF"));

                DebitNoteRpt rpt = new DebitNoteRpt();
                rpt.SetTitle("APPLICATION FEE FOR " + DateTime.Now.Year.ToString() + " / " + (DateTime.Now.Year + 1).ToString() + " ACADEMIC YEAR");
                rpt.SetListInvoiceDetail(ListInvDetail);
                rpt.ShowPreview();
            }
            else
            {
                ListInvDetail.Add(common.GetInvoiceDetail(Inv, "COE"));

                COERpt rpt = new COERpt();
                rpt.SetTitle("CERTIFICATE OF ENTITLEMENT");
                rpt.SetListInvoiceDetail(ListInvDetail);
                rpt.ShowPreview();
            }
           
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MsgPrintDN_Shown(object sender, EventArgs e)
        {
            if (Inv.Itemcode == "APPF")
            {
                this.comboBoxEdit1.SelectedIndex = 0;
            }
            else if (Inv.Itemcode == "COE")
            {
                this.comboBoxEdit1.SelectedIndex = 1;
            }
            else
            {
                DialogResult result = MessageBox.Show("This Fee don't need to print Debit Note");
                if (result == DialogResult.OK)
                {
                    this.Close();
                }
            }
        }
    }
}